<?php

$basePath = dirname(__DIR__);
$config = [
    'id' => 'app-api',
    'basePath' => $basePath,
    'name' => "api",
    'controllerNamespace' => 'api\controllers',
//    'defaultRoute' => 'route/api',
    'timeZone' => 'PRC',   //中国时区
    'charset' => 'UTF-8',   //默认, 万国码
    'language' => 'zh-CN',   //简体中文
    'bootstrap' => ['log'],
    'components' => [
        'request' => [
            'csrfParam' => '_csrf-api',
        ],
        'user' => [
            'identityClass' => 'common\models\db\User',
            'enableAutoLogin' => true,
            'identityCookie' => ['name' => '_identity-api', 'httpOnly' => true],
        ],
        'session' => [
            'name' => 'advanced-fztapi',
        ],
//        'log' => [
//            'traceLevel' => YII_DEBUG ? 3 : 0,
//            'targets' => [
//                [
//                    'class' => 'yii\log\FileTarget',
//                    'levels' => ['error', 'warning'],
//                ],
//            ],
//        ],
//        'errorHandler' => [
//            'errorAction' => 'site/error',
//        ],
    ],
    'modules' => [],
    'params' => [
        'wodrowRespSetup' => [
            'data' => ['code' => -1, 'message' => "失败"], // data公共返回
            'result' => ['code' => 0, 'message' => "ok"], // 响应体
            'resultCodeKey' => "code",
            'resultCodeSuccessValue' => 0,
            'resultMessageKey' => "message",
            'resultMessageSuccessValue' => "成功",
            'resultRalyOnData' => true,
            'resultDataKey' => "data",
            'resultDataDefaultValue' => [], // data公共返回
            'resultDataStatusKey' => "code",
            'resultDataStatusSuccessValue' => 0,
            'resultDataMsgKey' => "message",
            'resultDataMsgSuccessValue' => "成功",
        ],
    ],
];

$config = yii\helpers\ArrayHelper::merge(
    $config,
    \wodrow\yii\rest\Controller::getConfig()
);

$urlManagers = require(Yii::getAlias('@common/config/url-managers.php'));
$config['components']['urlManager'] = $urlManagers['urlManagerApi'];
$config['components']['response'] = [
    //返回异常统一处理
    'on beforeSend' => function ($event) {
        //$event->sender->format = 'json';
        Yii::$app->response->headers->set('Access-Control-Allow-Origin', '*');
        Yii::$app->response->headers->set('Access-Control-Allow-Methods', '*');
        Yii::$app->response->headers->set('Access-Control-Allow-Headers', '*');
        Yii::$app->response->headers->set('Access-Control-Request-Headers', '*');
    },
];

return $config;